/*
 * QueryBuilder.scala
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.squela
package sql

object QueryBuilder {

    def select(from: SqlResource)(fields: SqlField[_]*) = new Query {resource = from
                                                                     queryType = Select(fields: _*)}

    def select(from: String)(fields: SqlField[_]*): Query = select(Table(from, from(0).toString))(fields:_*)

    def insert(from: Table)(values: ->[_]*) = new Query {resource = from
                                                         queryType = Insert(values: _*)}
    def insert(from: String)(values: ->[_]*): Query = insert(Table(from, from(0).toString))(values:_*)

    def update(from: Table)(values: ->[_]*) = new Query {resource = from
                                                         queryType = Update(values: _*)}
    def update(from: String)(values: ->[_]*): Query = update(Table(from, from(0).toString))(values:_*)

    def delete(from: Table) = new Query {resource = from
                                         queryType = Delete()}
    def delete(from: String): Query = delete(Table(from, from(0).toString))

    def create(from: Table)(fields: SqlField[_]*) = {
        val query = new Query
        query.resource = from
        query.queryType = Create(fields: _*)
        query
    }

    def alterTable(from: Table)(alterType: AlterResource) = {
        val query = new Query
        query.resource = from
        query.queryType = alterType
        query
    }

}